<?php
function user_render_profile($data){
    
          			
			?>
  <div style="max-width:700px; margin:auto">
 <div class="web_profile">
	<div class="row">
		<div class="col-md-3">
        <img src="<?php  if($data['lavatar']){echo $data['lavatar'];}else{echo $data['avatar'];} ?>" class="img-rounded img-responsive" />

 	</div>
    
	
    <div class="col-md-9">
    <h3 class="username"><a href="<?php echo url_user($data['username']); ?>">	<?php echo show_username($data['username'],$data['name']); ?></a></h3>
    <div class="description"><i class="icon-quote-left colorfa"></i>  <?php echo $data['gioithieu']; ?>  <i class="icon-quote-right colorfa"></i></div>



					 <ul class="numbers">
                        <li>VIEW<strong><?php echo $data['views']; ?></strong></li>
                        <li>LIKE<strong><?php echo $data['likes']; ?></strong></li>
                        <li>COMMENT<strong><?php echo $data['comments']; ?></strong></li>
						<li>POST<strong><?php echo $data['comments']; ?></strong></li>
                        <li class="nobrdr">ALBUM<strong><?php echo $data['albums']; ?></strong></li>

                    </ul>

 
      <div class="clearfix"></div>
      <Br/>
      <ul class="list-inline pull-right">
       <?php
	  if($data['facebook'] ==1){?>
      <li> <i class="icon-facebook"></i> <a href="https://www.facebook.com/<?php echo $data['facebook_id'];?>">Vist My Facebook</a> </li>
      <?php }?>
      <li>   <i class="icon-mail"></i> <?php echo $data['email']; ?></li>
		</ul>
  </div> <!-- End of col-md-9 -->
 
  
 </div> <!-- End of row  -->
  </div> <!-- End of web profile -->
  </div><!-- End of row wap_700 -->
<?php
}


function album_render_info($data){
	
?>
  <div style="max-width:700px; margin:auto">
  

<div class="web_profile">
	<div class="row">
		<div class="col-md-3">
        <img src="<?php echo $data['image']; ?>" class="img-rounded img-responsive" />

 	</div>
    
	
    <div class="col-md-9">
    <h3 class="username">	<?php echo $data['name']; ?></h3>
    <div class="description"><i class="icon-quote-left colorfa"></i>  <?php echo $data['description']; ?>  <i class="icon-quote-right colorfa"></i></div>



					 <ul class="numbers">

                        <li>VIEW<strong><?php echo $data['views']; ?></strong></li>

                        <li>LIKE<strong><?php echo $data['likes']; ?></strong></li>
                        <li>COMMENT<strong><?php echo $data['comments']; ?></strong></li>

                        <li class="nobrdr">POST<strong><?php echo $data['posts']; ?></strong></li>

                    </ul>

 
      <div class="clearfix"></div>
      <Br/>
      <ul class="list-inline pull-right">
      <li><i class="icon-user"></i> levanvan.1986 </li>
      <li>   <i class="icon-time"></i> <?php echo time_ago($data['date_created']) ?></li>
		</ul>
  </div> <!-- End of col-md-6 -->
 
  
 </div> <!-- End of row  -->
  </div> <!-- End of web profile -->
  </div><!-- End of row wap_700 -->
<?php
}

function post_render_grid($data,$nav="",$type="", $pagerel = null){
	
	if(!$data){
		echo "<h1 style='text-align:center'>Không có dữ liệu</h1>";
		return;
	}

	$pagerel = $pagerel ? '&pagerel=' . $pagerel : null;
	
	if($type==""){
	
		if($_SESSION['list_news_list'] == 1) {$news_image = 'image_near_big';} else{$news_image = 'image_med';}
	
	
       
    echo "<div id=\"contentIndex\">";
	
 
   	if(count($data)==0){

   			echo "<h1 style='text-align:center'>Chưa có bài nào được đăng !</h1>";
			}else
			foreach($data as $row){
					$row['user'] = cache_get_user($row['username']);
		?>
				<div class="item">
					
					<div class="innerItem" id="innerItem-<?= $row['id'] . '-' . $row['type']; ?>" data-href="<?= $row['id']; ?>" data-rel="<?= $row['type']; ?>">
						<div class="innerItemHeader">
							<div class="userHeaderInfo">
								<img class="headerInfoAvatar" width="40" src="<?= $row['user']['avatar']; ?>" alt="<?= $row['username']; ?>" />
								<p class="font12 headerUsername"><a href="<?= HOME . 'user/' . $row['username']; ?>"><?=$row['username'];?></a></p>
								<p class="font11 pull-left headerUsername"><i class=" icon-time"> </i><?php echo time_ago($row['date_created']); ?> - </p>
								<p class="font11 pull-left headerUsername"><i class=" icon-folder-open"> </i><?php echo $row['cat_name']; ?></p>
								<div class="clr"></div> 
							</div>
							
							
							<h3><a class="hoverUnderline" href="<?php echo url_post($row['pid']) . $pagerel; ?>"><?php echo $row['title']; ?></a></h3>
							
						</div>
						<div class="clr"></div>
                    	<div class="wrap-inner-image">
                    		<?php
							if($row['type'] == 'video'){
								if($_SESSION['mobile'] == 0){
									echo '<span class="video_play_icon itemImage"><img src="'.BASE_URL. 'public/images/video-play-3-xxl.png" alt="video" /></span>';
								}else{
									echo '<a class="video_play_icon" href="'.url_post($row['pid']) . $pagerel.'"><img src="'.BASE_URL. 'public/images/video-play-3-xxl.png" alt="video" /></a>';
								}
								
							}else if($row['type'] == 'image'){
								if($row['image_gif'] == 1){
									if($_SESSION['mobile'] == 0){
										echo '<span class="gif_play_icon itemImage"><img width="60" src="'.BASE_URL. 'public/images/icon-gif-play.png" alt="video" /></span>';
									}else{
										echo '<a class="gif_play_icon" href="'.url_post($row['pid']) . $pagerel.'"><img width="60" src="'.BASE_URL. 'public/images/icon-gif-play.png" alt="video" /></a>';
									}
									
								}

							}
                    		?>
                            
                            <?php if($_SESSION['mobile']==0){?>
							<img class="itemImage img-responsive" data-toggle="modal" data-target="#popupElem-innerItem-<?= $row['id'] . '-' . $row['type']; ?>" src="<?php echo $row[$news_image]; ?>" alt=""  />
							<div class="urlId" style="display: none"><?= url_post($row['pid']); ?></div>
                            <?php }else{?>
                            	<a class="hoverUnderline" href="<?php echo url_post($row['pid']) . $pagerel; ?>"><img class=" img-responsive" src="<?php echo $row['image_med']; ?>" alt=""  /></a>
                            <?php }?>
						</div>
						<div class="wrapInnerItemInfo">
						
						<div class="wrapInfo">
                          	
                         
                               
                                   <div class="viewInfoMetadata "><i class="blue icon-eye-open"> </i> <?php echo $row['views']; ?></div>
                                   
                                   <div class="viewInfoMetadata "><i class="blue icon-comments"> </i> <?php echo $row['comments']; ?></div>
                                   <div class="viewInfoMetadata "><div class="fb-like" data-href="<?php echo url_post($row['pid']) ;?>" data-layout="button_count" data-action="like" data-show-faces="false" data-share="false"></div></div>
                               
							<div class="clr  margin5"></div>
                                
								
								
								
	
								<div class="clr"></div>
							</div><!-- end .itemInfo -->
						</div>
					</div><!-- end .innerItem -->
					
				</div><!-- end .item -->
                <?php
			}?>
               
               
               
               
               
           <?php    
      
       
    echo "</div>";

		 echo $nav; ?>
            
            
           
		
    <?php
	} // type= ""
	
	if($type=='album'){
		?>
          <div id="contentIndex">
   <?php	
			foreach($data as $row){
				
			?>
				<div class="item">
					<div class="innerItem" id="innerItem-1">
                    	<div class="wrap-inner-image">
                        
                       <a class="hoverUnderline" href="<?php echo url_album($row['id']); ?>">
							<img class="img-responsive"  src="<?php echo $row['image']; ?>" alt=""  />
						</a>
                        
							</div>
						<div class="wrapInnerItemInfo">
                        
                        
						<h3><a class="hoverUnderline" href="<?php echo url_album($row['id']); ?>"><?php echo $row['name']; ?></a></h3>
                        <p><?php echo $row['description']; ?></p>
                      
                        
						<div class="wrapInfo2">
                          	<div class="row">
                                	<div class="col-sm-4 col-xs-4"><i class="icon-file-text"> </i><?php echo $row['views']; ?></div>
                                   <div class="col-sm-4 col-xs-4"><i class="icon-thumbs-up-alt"> </i><?php echo $row['likes']; ?></div>
                                   <div class="col-sm-4 col-xs-4"><i class="icon-comments"> </i><?php echo $row['comments']; ?></div> 
                                </div>
							<div class="clr  margin5"></div>
                                
								
								<span class="pull-left font11 margin-right-10"><i class=" icon-time">  </i><?php echo time_ago($row['date_created']); ?></span>
								<span class="pull-right font11 margin-right-10"><i class=" icon-user">  </i><?php echo $row['username']; ?></span> 
	
								<div class="clr"></div>
							</div><!-- end .itemInfo -->
						</div>
					</div><!-- end .innerItem -->
					
				</div><!-- end .item -->
                <?php
			}?>
               
               
               
               
               
               
         
			</div><!-- end #contentIndex -->
          
        <?php
		
	}//End of type= album
}


function post_render_grid_list($data,$nav="",$type="", $pagerel = null){
	if(!$data){
	echo "<h1 style='text-align:center'>Không có dữ liệu</h1>";
	return;
}

$pagerel = $pagerel ? '&pagerel=' . $pagerel : null;

if($type==""){

	if($_SESSION['list_news_list'] == 1) {$news_image = 'image_near_big';} else{$news_image = 'image_med';}


	 
	echo "<div id=\"contentIndex\">";


	if(count($data)==0){

		echo "<h1 style='text-align:center'>Chưa có bài nào được đăng !</h1>";
	}else

		foreach($data as $row){
			$row['user'] = cache_get_user($row['username']);
		?>
				<div class="item">
					
					<div class="innerItem" id="innerItem-<?= $row['id'] . '-' . $row['type']; ?>" data-href="<?= $row['id']; ?>" data-rel="<?= $row['type']; ?>">
						<div class="innerItemHeader">
							<div class="userHeaderInfo">
								<img class="headerInfoAvatar" width="40" src="<?= $row['user']['avatar']; ?>" alt="<?= $row['username']; ?>" />
								<p class="font12 headerUsername"><a href="<?= HOME . 'user/' . $row['username']; ?>"><?=$row['username'];?></a></p>
								<p class="font11 pull-left headerUsername"><i class=" icon-time"> </i><?php echo time_ago($row['date_created']); ?> - </p>
								<p class="font11 pull-left headerUsername"><i class=" icon-folder-open"> </i><?php echo $row['cat_name']; ?></p>
								<div class="clr"></div> 
							</div>
							
							
							<h3><a class="hoverUnderline" href="<?php echo url_post($row['pid']) . $pagerel; ?>"><?php echo $row['title']; ?></a></h3>
							
						</div>
						<div class="clr"></div>
                    	<div class="wrap-inner-image">
                    		<?php
							if($row['type'] == 'video'){
								if($_SESSION['mobile'] == 0){
									echo '<span class="video_play_icon itemImage"><img src="'.BASE_URL. 'public/images/video-play-3-xxl.png" alt="video" /></span>';
								}else{
									echo '<a class="video_play_icon" href="'.url_post($row['pid']) . $pagerel.'"><img src="'.BASE_URL. 'public/images/video-play-3-xxl.png" alt="video" /></a>';
								}
								
							}else if($row['type'] == 'image'){
								if($row['image_gif'] == 1){
									if($_SESSION['mobile'] == 0){echo 'here';
										echo '<span class="gif_play_icon itemImage"><img width="60" src="'.BASE_URL. 'public/images/icon-gif-play.png" alt="video" /></span>';
									}else{
										echo '<a class="gif_play_icon" href="'.url_post($row['pid']) . $pagerel.'"><img width="60" src="'.BASE_URL. 'public/images/icon-gif-play.png" alt="video" /></a>';
									}
									
								}
							}
                    		?>
                            
                            <?php if($_SESSION['mobile']==0){?>
							<img class="itemImage img-responsive" data-toggle="modal" data-target="#popupElem-innerItem-<?= $row['id'] . '-' . $row['type']; ?>" src="<?php echo $row[$news_image]; ?>" alt=""  />
							<div class="urlId" style="display: none;"><?= url_post($row['pid']); ?></div>
                            <?php }else{?>
                            	<a class="hoverUnderline" href="<?php echo url_post($row['pid']) . $pagerel; ?>"><img class=" img-responsive" src="<?php echo $row['image_med']; ?>" alt=""  /></a>
                            <?php }?>
						</div>
						<div class="wrapInnerItemInfo">
						
						<div class="wrapInfo">
                          	
                         
                               
                                   <div class="viewInfoMetadata "><i class="blue icon-eye-open"> </i> <?php echo $row['views']; ?></div>
                                   
                                   <div class="viewInfoMetadata "><i class="blue icon-comments"> </i> <?php echo $row['comments']; ?></div>
                                   <div class="viewInfoMetadata "><div class="fb-like" data-href="<?php echo url_post($row['pid']) ;?>" data-layout="button_count" data-action="like" data-show-faces="false" data-share="false"></div></div>
                               
							<div class="clr  margin5"></div>
                                
								
								
								
	
								<div class="clr"></div>
							</div><!-- end .itemInfo -->
						</div>
					</div><!-- end .innerItem -->
					
				</div><!-- end .item -->
                <?php
			}?>
               
                 
               
           <?php    
      
       
    echo "</div>";

		 ?>
            
            
           
		
    <?php
	} // type= ""
	
	if($type=='album'){
		?>
	          <div id="contentIndex">
	   <?php	
				foreach($data as $row){
					
				?>
					<div class="item">
						<div class="innerItem" id="innerItem-1">
	                    	<div class="wrap-inner-image">
	                        
	                       <a class="hoverUnderline" href="<?php echo url_album($row['id']); ?>">
								<img class="img-responsive"  src="<?php echo $row['image']; ?>" alt=""  />
							</a>
	                        
								</div>
							<div class="wrapInnerItemInfo">
	                        
	                        
							<h3><a class="hoverUnderline" href="<?php echo url_album($row['id']); ?>"><?php echo $row['name']; ?></a></h3>
	                        <p><?php echo $row['description']; ?></p>
	                      
	                        
							<div class="wrapInfo2">
	                          	<div class="row">
	                                	<div class="col-sm-4 col-xs-4"><i class="icon-file-text"> </i><?php echo $row['views']; ?></div>
	                                   <div class="col-sm-4 col-xs-4"><i class="icon-thumbs-up-alt"> </i><?php echo $row['likes']; ?></div>
	                                   <div class="col-sm-4 col-xs-4"><i class="icon-comments"> </i><?php echo $row['comments']; ?></div> 
	                                </div>
								<div class="clr  margin5"></div>
	                                
									
									<span class="pull-left font11 margin-right-10"><i class=" icon-time">  </i><?php echo time_ago($row['date_created']); ?></span>
									<span class="pull-right font11 margin-right-10"><i class=" icon-user">  </i><?php echo $row['username']; ?></span> 
		
									<div class="clr"></div>
								</div><!-- end .itemInfo -->
							</div>
						</div><!-- end .innerItem -->
						
					</div><!-- end .item -->
	                <?php
				}?>
	               
	               
	               
	               
	               
	               
	         
				</div><!-- end #contentIndex -->
	          
	        <?php
			
		}//End of type= album

}



function post_render_grid_item($data,$type=''){
	if(!$data){
		
		return;
	}
			if($type!='album'){
				if($_SESSION['list_news_list'] == 1) {$news_image = 'image_near_big';} else{$news_image = 'image_med';}
							foreach($data as $row){
							$row['user'] = cache_get_user($row['username']);
		?>
				<div class="item">
					
					<div class="innerItem" id="innerItem-<?= $row['id'] . '-' . $row['type']; ?>" data-href="<?= $row['id']; ?>" data-rel="<?= $row['type']; ?>">
						<div class="innerItemHeader">
							<div class="userHeaderInfo">
								<img class="headerInfoAvatar" width="40" src="<?= $row['user']['avatar']; ?>" alt="<?= $row['username']; ?>" />
								<p class="font12 headerUsername"><a href="<?= HOME . 'user/' . $row['username']; ?>"><?=$row['username'];?></a></p>
								<p class="font11 pull-left headerUsername"><i class=" icon-time"> </i><?php echo time_ago($row['date_created']); ?> - </p>
								<p class="font11 pull-left headerUsername"><i class=" icon-folder-open"> </i><?php echo $row['cat_name']; ?></p>
								<div class="clr"></div> 
							</div>
							
							
							<h3><a class="hoverUnderline" href="<?php echo url_post($row['pid']) . $pagerel; ?>"><?php echo $row['title']; ?></a></h3>
							
						</div>
						<div class="clr"></div>
                    	<div class="wrap-inner-image">
                    		<?php
							if($row['type'] == 'video'){
								if($_SESSION['mobile'] == 0){
									echo '<span class="video_play_icon itemImage"><img src="'.BASE_URL. 'public/images/video-play-3-xxl.png" alt="video" /></span>';
								}else{
									echo '<a class="video_play_icon" href="'.url_post($row['pid']) . $pagerel.'"><img src="'.BASE_URL. 'public/images/video-play-3-xxl.png" alt="video" /></a>';
								}
								
							}else if($row['type'] == 'image'){
								if($row['image_gif'] == 1){
									if($_SESSION['mobile'] == 0){
										echo '<span class="gif_play_icon itemImage"><img width="60" src="'.BASE_URL. 'public/images/icon-gif-play.png" alt="video" /></span>';
									}else{
										echo '<a class="gif_play_icon" href="'.url_post($row['pid']) . $pagerel.'"><img width="60" src="'.BASE_URL. 'public/images/icon-gif-play.png" alt="video" /></a>';
									}
									
								}

							}
                    		?>
                            
                            <?php if($_SESSION['mobile']==0){?>
							<img class="itemImage img-responsive" data-toggle="modal" data-target="#popupElem-innerItem-<?= $row['id'] . '-' . $row['type']; ?>" src="<?php echo $row[$news_image]; ?>" alt=""  />
							<div class="urlId" style="display: none;"><?= url_post($row['pid']); ?></div>
                            <?php }else{?>
                            	<a class="hoverUnderline" href="<?php echo url_post($row['pid']) . $pagerel; ?>"><img class=" img-responsive" src="<?php echo $row['image_med']; ?>" alt=""  /></a>
                            <?php }?>
						</div>
						<div class="wrapInnerItemInfo">
						
						<div class="wrapInfo">
                          	
                         
                               
                                   <div class="viewInfoMetadata "><i class="blue icon-eye-open"> </i> <?php echo $row['views']; ?></div>
                                   
                                   <div class="viewInfoMetadata "><i class="blue icon-comments"> </i> <?php echo $row['comments']; ?></div>
                                   <div class="viewInfoMetadata "><div class="fb-like" data-href="<?php echo url_post($row['pid']) ;?>" data-layout="button_count" data-action="like" data-show-faces="false" data-share="false"></div></div>
                               
							<div class="clr  margin5"></div>
                                
								
								
								
	
								<div class="clr"></div>
							</div><!-- end .itemInfo -->
						</div>
					</div><!-- end .innerItem -->
					
				</div><!-- end .item -->
								<?php
							}
			}else{
			//Type == album
					foreach($data as $row){
						
					?>
						<div class="item">
							<div class="innerItem" id="innerItem-1">
								<div class="wrap-inner-image">
								  <a class="hoverUnderline" href="<?php echo url_album($row['id']); ?>">
							<img class="img-responsive"  src="<?php echo $row['image']; ?>" alt=""  />
								</a>
								</div>
								<div class="wrapInnerItemInfo">
								
								
								<h3><a class="hoverUnderline" href="<?php echo url_album($row['pid']); ?>"><?php echo $row['name']; ?></a></h3>
								<p><?php echo $row['description']; ?></p>
							  
								
								<div class="wrapInfo2">
									<div class="row">
											<div class="col-sm-4 col-xs-4"><i class="icon-file-text"> </i><?php echo $row['views']; ?></div>
										   <div class="col-sm-4 col-xs-4"><i class="icon-thumbs-up-alt"> </i><?php echo $row['likes']; ?></div>
										   <div class="col-sm-4 col-xs-4"><i class="icon-comments"> </i><?php echo $row['comments']; ?></div> 
										</div>
									<div class="clr  margin5"></div>
										
										
										<span class="pull-left font11 margin-right-10"><i class=" icon-time">  </i><?php echo time_ago($row['date_created']); ?></span>
										<span class="pull-right font11 margin-right-10"><i class=" icon-user">  </i><?php echo $row['username']; ?></span> 
			
										<div class="clr"></div>
									</div><!-- end .itemInfo -->
								</div>
							</div><!-- end .innerItem -->
							
						</div><!-- end .item -->
						<?php
					
					} //End of foreach
			} // End of else if ==album
}

function post_render_grid_item_list($data,$type=''){

	if(!$data){

		return;
	}
	if($type!='album'){
		if($_SESSION['list_news_list'] == 1) {$news_image = 'image_near_big';} else{$news_image = 'image_med';}
		foreach($data as $row){

			$row['user'] = cache_get_user($row['username']);

			?>
								<div class="item">
								
									<div class="innerItem" id="innerItem-<?= $row['id'] . '-' . $row['type'];?>" data-href="<?= $row['id']; ?>" data-rel="<?= $row['type']; ?>">
										<div class="innerItemHeader">
											<div class="userHeaderInfo">
												<img class="headerInfoAvatar" width="40" src="<?= $row['user']['avatar']; ?>" alt="<?= $row['username']; ?>" />
												<p class="font12 headerUsername"><a href="<?= HOME . 'user/' . $row['username']; ?>"><?=$row['username'];?></a></p>
												<p class="font11 pull-left headerUsername"><i class=" icon-time"> </i><?php echo time_ago($row['date_created']); ?> - </p>
												<p class="font11 pull-left headerUsername"><i class=" icon-folder-open"> </i><?php echo $row['cat_name']; ?></p>
												<div class="clr"></div> 
											</div>
											
											
											<h3><a class="hoverUnderline" href="<?php echo url_post($row['pid']) . $pagerel; ?>"><?php echo $row['title']; ?></a></h3>
											
										</div>
										<div class="clr"></div>
										<div class="wrap-inner-image">
										<?php
										if($row['type'] == 'video'){
											if($_SESSION['mobile'] == 0){
												echo '<span class="video_play_icon itemImage"><img src="'.BASE_URL. 'public/images/video-play-3-xxl.png" alt="video" /></span>';
											}else{
												echo '<a class="video_play_icon hoverUnderline" href="'.url_post($row['pid']) . $pagerel.'"><img src="'.BASE_URL. 'public/images/video-play-3-xxl.png" alt="video" /></a>';
											}
											
										}else if($row['type'] == 'image'){
											if($row['image_gif'] == 1){
												if($_SESSION['mobile'] == 0){
													echo '<span class="gif_play_icon itemImage"><img width="60" src="'.BASE_URL. 'public/images/icon-gif-play.png" alt="video" /></span>';
												}else{
													echo '<a class="gif_play_icon" href="'.url_post($row['pid']) . $pagerel.'"><img width="60" src="'.BASE_URL. 'public/images/icon-gif-play.png" alt="video" /></a>';
												}
												
											}

										}
			                    		?>
							  <?php if($_SESSION['mobile']==0){?>
							<img class="itemImage img-responsive" data-toggle="modal" data-target="#popupElem-innerItem-<?= $row['id'] . '-' . $row['type']; ?>" src="<?php echo $row[$news_image]; ?>" alt=""  />
							<div class="urlId" style="display: none;"><?= url_post($row['pid']); ?></div>
                            <?php }else{?>
                            	<a class="hoverUnderline" href="<?php echo url_post($row['pid']) . $pagerel; ?>"><img class=" img-responsive" src="<?php echo $row['image_med']; ?>" alt=""  /></a>
                            <?php }?>
										</div>
										
										<div class="wrapInnerItemInfo">
											
											<div class="wrapInfo">
                          	
                                	<!-- <div class="col-sm-4 col-xs-4"><i class="blue  icon-eye-open"> </i><?php echo k_format($row['views']); ?></div>
                                   <div class="col-sm-4 col-xs-4"><i class="blue icon-thumbs-up-alt"> </i><?php echo k_format($row['likes']); ?></div>
                                   <div class="col-sm-4 col-xs-4"><i class="blue icon-comments"> </i><?php echo k_format($row['comments']); ?></div> --> 
                               
                                   <div class="viewInfoMetadata "><i class="blue icon-eye-open"> </i> <?php echo k_format($row['views']); ?></div>
                                   
                                   <div class="viewInfoMetadata "><i class="blue icon-comments"> </i> <?php echo k_format($row['comments']); ?></div>
                                   <div class="viewInfoMetadata "><div class="fb-like" data-href="<?php echo url_post($row['pid']) ;?>" data-layout="button_count" data-action="like" data-show-faces="false" data-share="false"></div></div>
                               	
							<div class="clr  margin5"></div>
                                
								
								
								
	
								<div class="clr"></div>
							</div><!-- end .itemInfo -->
										</div>
										
									</div><!-- end .innerItem -->
									
								</div><!-- end .item -->
								<?php
							}
			}else{
			//Type == album
					foreach($data as $row){
						
					?>
						<div class="item">
							<div class="innerItem" id="innerItem-1">
								<div class="wrap-inner-image">
								  <a class="hoverUnderline" href="<?php echo url_album($row['id']); ?>">
							<img class="img-responsive"  src="<?php echo $row['image']; ?>" alt=""  />
								</a>
								</div>
								<div class="wrapInnerItemInfo">
								
								
								<h3><a class="hoverUnderline" href="<?php echo url_album($row['pid']); ?>"><?php echo $row['name']; ?></a></h3>
								<p><?php echo $row['description']; ?></p>
							  
								
								<div class="wrapInfo2">
									<div class="row">
											<div class="col-sm-4 col-xs-4"><i class="icon-file-text"> </i><?php echo $row['views']; ?></div>
										   <div class="col-sm-4 col-xs-4"><i class="icon-thumbs-up-alt"> </i><?php echo $row['likes']; ?></div>
										   <div class="col-sm-4 col-xs-4"><i class="icon-comments"> </i><?php echo $row['comments']; ?></div> 
										</div>
									<div class="clr  margin5"></div>
										
										
										<span class="pull-left font11 margin-right-10"><i class=" icon-time">  </i><?php echo time_ago($row['date_created']); ?></span>
										<span class="pull-right font11 margin-right-10"><i class=" icon-user">  </i><?php echo $row['username']; ?></span> 
			
										<div class="clr"></div>
									</div><!-- end .itemInfo -->
								</div>
							</div><!-- end .innerItem -->
							
						</div><!-- end .item -->
						<?php
					
					} //End of foreach
			} // End of else if ==album
}

function menu_render_category(){
	$cache = new cache;
	$dt=$cache->load('menu_category');
	if(!$dt){
		$db= new db;
		$db->connect();
		$db->query('select * from category order by name asc');
		$r=$db->fetchAll();
		$dt="";
		foreach($r as $row){
		 $val="<li><a href='".url_category($row['id'],$row['alias'])."'>".$row['name']."</a></li>";
		 $dt.=$val;
		}
		$cache->save('menu_category',$dt,300);
	}
	
	echo $dt;
	return 1;
}

/*
 * Render view most day/week/month
 */
	function template_render_top_view(){
		$date = date('Y-m-d');
		$model = new Model();
		$model->where = "last_update_view = '" . $date . "'";
		$model->limit = '5';
		$model->order = 'view_day DESC';
		$model->getdata('index_post');
		$data['result_day_most_views'] = $model->fetchAll();

		?>
		<div class="rightBlock" id="rightNewThread">
						<h4 class="rightBlockTitle">
							Xem nhiều - 
							<a id="rightMostDayView" class="clickShowView" href="">ngày</a><span></span>
							<a id="rightMostWeekView" class="clickShowView" href="">tuần</a><span></span>
							<a id="rightMostMonthView" class="clickShowView" href="">tháng</a>
						</h4>
						
						<div class="innerRightBlock" id="show_rightMostDayView">
						
						<?php if($data['result_day_most_views']){
						
						
							foreach($data['result_day_most_views'] as $day_news){
								$news = get_post($day_news['id']);
						?>
								<div class="rightItem">
									<a class="wrapRightImage" href="<?php echo url_post($day_news['id'],'viewd'); ?>"><img src="<?= $news['image_small']; ?>" style="max-width:90px" alt=""></a>
									<h4>
										<a class="rightItemTitle" href="<?php echo url_post($day_news['id'],'viewd'); ?>"><?= $news['title'];?></a> 
										
									</h4>
									<span class="pull-left font11 margin-right-10"><i class=" icon-eye-open"> </i><?= k_format($news['views']); ?></span> 
									<span class="pull-left font11 margin-right-10"><i class="icon-thumbs-up-alt"> </i><?= k_format($news['likes']); ?></span> 
									<span class="pull-left font11 margin-right-10"><i class="icon-comments"> </i><?= k_format($news['comments']); ?></span>
                                    <span class="pull-left font11 margin-right-10"><a class="rightItemAuthor" href="<?php echo url_user($news['username']) ?>"><i class="icon-user"> </i><?php echo $news['username'] ?></a></span>
									<div class="clr"></div>
								</div><!-- end .rightItem -->
						<?php 
							}
						}else{//else if ($data['result_day_most_views'])
						?>
						
							
							
						
						<?php }?>
						</div><!-- end innerRightBlock -->
							
						<div class="innerRightBlock" id="show_rightMostWeekView"></div>
						
						<div class="innerRightBlock" id="show_rightMostMonthView"></div>	
                        
                        	</div> <!-- END OF rightNewThread --><?
	}
	
	
	/*
 * Render pickup Post
 */
	function template_render_pickup(){
		$c=new cache;
		$dt=$c->load('pickup_post');
		if(!$dt){
			$db=new db;
			$db->connect();
			$db->query('select id from index_post where pick =1  order by id desc limit 0,5');
			$data=$db->fetchAll();
			foreach($data as $row){
			$dt[]=get_post($row['id']);
			}
			$c->save('pickup_post',$dt,1200);
			$db->close();
		}
		

		?>
		<div class="rightBlock" id="rightNewThread">
						<h4 class="rightBlockTitle">
							PUN TUYỂN CHỌN
						</h4>
						
						<div class="innerRightBlock1">
						
						<?php if($dt){
							
							foreach($dt as $row){
								
						?>
								<div class="rightItem">
									<a class="wrapRightImage" href="<?php echo url_post($row['id'],'pick'); ?>"><img src="<?= $row['image_small']; ?>" style="max-width:90px" alt=""></a>
									<h4>
										<a class="rightItemTitle" href="<?php echo url_post($row['id'],'pick'); ?>"><?= $row['title'];?></a> 
										
									</h4>
									<span class="pull-left font11 margin-right-10"><i class=" icon-eye-open"> </i><?= $row['views']; ?></span> 
									<span class="pull-left font11 margin-right-10"><i class="icon-thumbs-up-alt"> </i><?= $row['likes']; ?></span> 
									<span class="pull-left font11 margin-right-10"><i class="icon-comments"> </i><?= $row['comments']; ?></span>
                                   <span class="pull-left font11 margin-right-10"><a class="rightItemAuthor" href="<?php echo url_user($row['username']) ?>"><i class="icon-user"> </i><?php echo $news['username'] ?></a></span>
									<div class="clr"></div>
								</div><!-- end .rightItem -->
						<?php 
							}
						}else{//else if ($data['result_day_most_views'])
						?>
						
							
							
						
						<?php }?>
						</div><!-- end innerRightBlock -->
							
						
                        
                        	</div> <!-- END OF rightNewThread --><?
	}
	
	
	function template_render_facebook(){
			

		?>
		<div class="rightBlock" id="rightNewThread">
						<h4 class="rightBlockTitle">
							LIKE CHÚNG TÔI TRÊN FACEBOOK
						</h4>
						
						<div class="innerRightBlock1">
						 <iframe src="//www.facebook.com/plugins/likebox.php?href=http://www.facebook.com/giaitriviet24h&amp;width=320&amp;height=258&amp;colorscheme=light&amp;show_faces=true&amp;stream=false&amp;header=false&amp;appId=308481842558254" scrolling="no" frameborder="0" bgcolor="#F3F3F3" style="border:none; overflow:hidden; width:290px; height:258px; " allowTransparency="true"></iframe>
						</div>
							
						
                        
                        	</div> <!-- END OF rightNewThread --><?
	}


function template_render_album_related($data){

					if($data && $data['list_item']){
					?>
                    		<div class="view_breadcrumb"><?php echo $data['name'] ;?></div>
                            <div class="body_right">
                           
                           	<div id="relatedPosts">
                            
                            <?php if($data['list_item']){ 
										foreach($data['list_item'] as $rp){?>
                                        <div class="item">
                                            <div class="innerItem" id="innerItem-2">
                                                <a  href="<?php echo url_post($rp['id'],'album'); ?>"><img class="itemImage" src="<?php echo $rp['image_small']; ?>" alt="" /></a>
                                                <div class="moreinfo">
                                                    <h3><a class="right" href="<?php echo url_post($rp['id'],'album'); ?>"><?php echo $rp['title']; ?></a></h3>
                                                </div>
                                            </div><!-- end .innerItem -->
                                    </div><!-- end .item -->
							<?php 
										}
										?>
                                       <Br/>          <Br/>
                                        <?php
							}?>
							
						</div><!--  #relatedPosts-->

            
                            </div>
                    		<div class="bottom_right">
                            	<ul class="list-inline moreinfo2">
                                <li><?php echo $data['album']['likes']; ?> Likes</li>
                                <li><?php echo $data['album']['comments']; ?> Comments</li>
                                <li><?php echo $data['album']['posts']; ?> Posts</li>
                                    <li class="pull-right view_all"><a href="<?php echo url_album($data['album']['id']); ?>"><span class="glyphicon glyphicon-th-list"></span> Xem Hết </a></li>
                              
                                </ul>
                            </div>
                              <bR/>
                          <bR/>  
                           <?php }
}
	
function render_col_right($where='',$data=''){
		if($where=='post'){
		 template_render_album_related($data);
		 
		}
		
		 template_render_facebook(); 
         echo "<Br/>";
         echo "<Br/>";
		 template_render_top_view();
		 echo "<br />";
		 template_render_pickup(); 		
         echo "<Br/>";
         echo "<img src=\"http://taiiwin.vn/wp-content/uploads/iwin-game.gif\" />";	
}

?>